package dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;

import bean.Comment;
import dao.CommentDao;

//Apply
public class CommentDaoImpl extends BaseDao implements CommentDao {

	@Override
	public Integer selectCommentbyid(Integer id) {
		try {
			Object query2 = query.query("select * from comment where commentid=?", id,
					new BeanHandler<Comment>(Comment.class));
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer deleteCommentbyid(Integer id) {
		try {
			return query.update("delete from comment where commentid=?", id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer updateComment(Comment info) {
		String sql = "update comment set userid=?,objectid=?,commenttype=?,commentcontent=?,"
				+ "commenttime=?,state=?,time=?,type=?, where commentid=?";
		try {
			return query.update(sql, info.getUserid(), info.getObjectid(), info.getCommenttype(),
					info.getCommentcontent(), info.getCommenttime(), info.getState(), info.getTime(), info.getType());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer addComment(Comment info) {
		String sql = "insert into comment(userid,objectid,commenttype,commentcontent,"
				+ "commenttime,state,time,type) VALUES(?,?,?,?,?,?,?,?);";
		try {
			return query.update(sql, info.getUserid(), info.getObjectid(), info.getCommenttype(),
					info.getCommentcontent(), info.getCommenttime(), info.getState(), info.getTime(), info.getType());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

}
